﻿namespace DreamBuilder.Common
{
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class MessageShow
    {
        public static string ShowMessageBox(string strMessage)
        {
            if ((strMessage != null) && (strMessage.Trim().Length > 0))
            {
                strMessage = strMessage.Replace("\"", "#").Replace("\n", @"\n").Replace("\r", @"\r");
            }
            string str = "<script language=\"javascript\">\n";
            return (((str + "var errmsg;\n") + "errmsg=\"" + strMessage + "\";\n") + "window.alert(errmsg);</script>");
        }

        public static void ShowMessageBox(Page _page, string strMessage)
        {
            if ((strMessage != null) && (strMessage.Trim().Length > 0))
            {
                strMessage = strMessage.Replace("\"", "#").Replace("\n", @"\n").Replace("\r", @"\r");
            }
            string script = "<script language=\"javascript\">\n";
            script = ((script + "var errmsg;\n") + "errmsg=\"" + strMessage + "\";\n") + "window.alert(errmsg);</script>";
            if (!_page.IsClientScriptBlockRegistered("showMessageBox"))
            {
                _page.RegisterStartupScript("showMessageBox", script);
            }
        }

        public static void ShowMessageBox(Literal lit, string strMessage)
        {
            if ((strMessage != null) && (strMessage.Trim().Length > 0))
            {
                strMessage = strMessage.Replace("\"", "#").Replace("\n", @"\n").Replace("\r", @"\r");
            }
            string str = "<script language=\"javascript\">\n";
            str = ((str + "var errmsg;\n") + "errmsg=\"" + strMessage + "\";\n") + "window.alert(errmsg);</script>";
            lit.Text = str;
            lit.Visible = true;
        }
    }
}

